<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">

<head>
    <meta charset="UTF-8">
    <title>镜像管理</title>
    <link href="__PUBLIC__/layui/css/layui.css" rel="stylesheet" />
</head>

<body>
<div class="admin-main">
    <blockquote class="layui-elem-quote">
        <button  class="layui-btn layui-btn-small add">
            <i class="layui-icon">&#xe608;</i> 添加服务器镜像
        </button>
    </blockquote>
    <fieldset class="layui-elem-field">
        <legend>镜像列表</legend>
        <div class="layui-field-box">
            <table class="layui-table">
                <thead>
                <tr>
                    <th>id</th>
                    <th>服务平台</th>
                    <th>镜像区域</th>
                    <th>镜像名称</th>
                    <th>镜像id</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="listcontent">
                </tbody>
            </table>
        </div>
    </fieldset>
    <div class="admin-table-page">
        <div id="page" class="page">
        </div>
    </div>
</div>
<script id="demo" type="text/html">
    <tr>
        <td>{{d.keyid}}</td>
        <td>{{ d.type}}</td>
        <td>{{ d.regionstitle}}</td>
        <td>{{d.name}}</td>
        <td>{{d.url}}</td>
        <td>
            <a data="{{d.keyid}}" class="layui-btn layui-btn-mini layui-btn-normal edit"><i class="layui-icon">&#xe642;</i>编辑</a>
            <a  data="{{d.keyid}}" class="layui-btn layui-btn-danger layui-btn-mini del"><i class="layui-icon">&#xe640;</i>删除</a>
        </td>
    </tr>
</script>
<script type="text/javascript" src="__PUBLIC__/layui/layui.js"></script>
<script>
    var form,layer,$;
    var imgaddurl="{:U('MyService/imgInsert')}";
    var imgdelurl="{:U('MyService/delImg')}";
    layui.use(['layer', 'form','laypage','laytpl'], function () {
        var laypage = layui.laypage,laytpl = layui.laytpl;
        form = layui.form();
        $ = layui.jquery
        layer=layui.layer;
        var pagelistdate;
        var curr;

        laypage({
            cont: 'page',
            pages: {$page} //总页数
            ,
            groups: 5 //连续显示分页数
            ,
            jump: function(obj, first) {
                curr = obj.curr;
                listcontent.innerHTML='';
                $.ajax({
                    type: "GET",
                    url: "",
                    data: { p:curr},
                    async: false,
                    success: function(date){
                        if(date['code']==101) {
                            pagelistdate =date .data;
                            layui.each(date.data, function (k, v) {
                                var getTpl = demo.innerHTML;
                                laytpl(getTpl).render(v, function (html) {
                                    listcontent.innerHTML += html;
                                });
                            });
                        }else{
                            listcontent.innerHTML='';
                        }
                    }
                });
                caozuo();
            }
        });

        $('.add').click(function(){
            $.get(imgaddurl,function(data){
                if(data.code == '4001'){
                    layer.msg(data.msg,{icon: 5});
                    return;
                }
                layer.open({
                    title:'添加镜像',
                    type: 1,
                    skin: 'layui-layer-rim',
                    area: ['550px','550px'],
                    content: data
                });
            });
        });

        function caozuo(){
            $('.edit').click(function () {
                var id = $(this).attr('data');
                $.get(imgaddurl, {keyid: id}, function (data) {
                    if (data.code == '4001') {
                        layer.msg(data.msg, {icon: 5});
                    }
                    layer.open({
                        title: '修改镜像',
                        type: 1,
                        skin: 'layui-layer-rim',
                        area: ['550px','550px'],
                        content: data,
                    });
                });
            });

            $('.del').click(function () {
                var id = $(this).attr('data');
                _this=$(this);
                layer.confirm('确认删除镜像吗?', {
                    icon: 3,
                    skin: 'layer-ext-moon',
                    btn: ['确认','取消']
                }, function(){
                    $.post(imgdelurl,{keyid:id},function(data){
                        if(data.code=='101'){
                            layer.msg(data.msg, {
                                icon: 6,
                                time: 2000
                            }, function(){
                                layer.closeAll();
                                _this.parent().parent().remove();
                            });

                        }else{
                            layer.msg(data.msg,{icon: 5});
                        }
                    });
                });
            });
        }
    });
</script>
</body>

</html>